Inside Macintosh: Sound

| Previous | Chapter contents | Chapter top | Section top | Next |

The Format 2 Sound Resource

The SndPlay function can also play format 2 'snd ' resources, which are designed for use only with sampled sounds. The SndPlay function supports this format by automatically opening a sound channel and using the bufferCmd command to send the data contained in the resource to the channel.

Figure 1-20 illustrates the fields of a format 2 'snd ' resource. The reference count field is for your application's use and is not used by the Sound Manager. The number of sound commands field and the sound command fields are the same as described in a format 1 resource. The last field of this resource contains the sampled sound. The first command should be either a soundCmd command or bufferCmd command with the data offset bit set in the command to specify the location of this sampled sound header.

Listing 1-51 shows a resource specification that illustrates the structure of a format 2 'snd ' resource.

Listing 51 A format 2 'snd ' resource

data 'snd ' (9003, "Pig Squeal", purgeable) {
    /*the sound resource header*/
    $"0002"             /*format type*/
    $"0000"             /*reference count for application's use*/
    /*the sound command*/
    $"0001"             /*number of sound commands that follow (1)*/
    $"8051"             /*command 1--bufferCmd*/
    $"0000"             /*param1 = 0*/
    $"0000000E"         /*param2 = offset to sound header (14 bytes)*/
    /*the sampled sound header*/
    $"00000000"         /*pointer to data (it follows immediately)*/
    $"00000BB8"         /*number of bytes in sample (3000 bytes)*/
    $"56EE8BA3"         /*sampling rate of this sound (22 kHz)*/
    $"000007D0"         /*starting of the sample's loop point*/
    $"00000898"         /*ending of the sample's loop point*/
    $"00"               /*standard sample encoding*/
    $"3C"               /*baseFrequency at which sample was taken*/
    $"80 80 81 82 84 87 93 84"              /*the sampled-sound data*/
    $"6F 68 6D 65 72 7B 82 88"
    $"91 8E 8D 8F 86 7E 7C 79"
    $"6F 6D 71 70 70 79 7F 81"
    $"89 8F 8D 8B"      /*rest of data omitted in this example*/
};

Remember that format 2 'snd ' resources are obsolete. You should create only format 1 'snd ' resources.


© 1998 Apple Computer, Inc.

| Previous | Chapter contents | Chapter top | Section top | Next |